function result = ASSIGN_CLUSTER(dataset,cluster_num)
%ASSIGN_CLUSTER Compute cluster position of points 
%   ASSIGN_CLUSTER(dataset,cluster_num) will partition the 'dataset'
%   according to K-means clustering algorithm. It will partition it into
%   'cluster_num' number of clusters. The function will return a single
%   array showing the position of the differnt points in 'dataset'
%   NOTE: It is assumed that the dataset has only 3 attributes per point

% Split 'dataset' into the 3 attributes
A = dataset(1,:);
B = dataset(2,:);
C = dataset(3,:);

% Assign center point values randomly from the data
index = randperm(length(A));
for i = 1:cluster_num
    A_center(i) = A(index(i));
    B_center(i) = B(index(i));
    C_center(i) = C(index(i));
end

% Number of iterations 
iteration = 1;
% Finding cluster positions
cluster_position = NEAREST_DISTANCE(A,B,C,A_center,B_center,C_center);
% storing it for later comparison
cluster_position_set(iteration,:) = cluster_position;
% Calculating new center points
[A_center,B_center,C_center] = CLUSTER_MEAN(cluster_position,A,B,C);

% Increment iterations
iteration = iteration + 1;

% Finding cluster positions
cluster_position = NEAREST_DISTANCE(A,B,C,A_center,B_center,C_center);
% storing it for later comparison
cluster_position_set(iteration,:) = cluster_position;
% Calculating new center points
[A_center,B_center,C_center] = CLUSTER_MEAN(cluster_position,A,B,C);

% Increment iterations
iteration = iteration + 1;

while( ~(isequal(cluster_position_set(iteration-1,:), cluster_position_set(iteration-2,:))) )
    % Finding cluster positions
    cluster_position = NEAREST_DISTANCE(A,B,C,A_center,B_center,C_center);
    % storing it for later comparison
    cluster_position_set(iteration,:) = cluster_position;
    % Calculating new center points
    [A_center,B_center,C_center] = CLUSTER_MEAN(cluster_position,A,B,C);
    % Increment iterations
    iteration = iteration + 1;
end

result = cluster_position_set(iteration-1,:);
